package com.aiyo.controller;


import com.aiyo.entity.BaseDictionary;
import com.aiyo.service.BaseDictionaryService;
import com.baomidou.mybatisplus.plugins.pagination.PageHelper;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;

import java.util.List;

/**
 * <p>
 * 字典表 前端控制器
 * </p>
 *
 * @author ylc
 * @since 2020-04-13
 */
@RestController
@Api(value = "字典表-管理", tags = "模块:字典表-管理")
@RequestMapping("/baseDictionary")
public class BaseDictionaryController {

    @Autowired
    private BaseDictionaryService baseDictionaryService;

    @ApiOperation("查询列表")
    @GetMapping("/list")
    public JsonData list(PageReqParams pageReqParams) {
        PageHelper.startPage(pageReqParams.getPage(), pageReqParams.getPageSize());
        List<BaseDictionary> list = baseDictionaryService.list();
        PageInfo<BaseDictionary> info = new PageInfo<>(list);
        return JsonData.buildSuccess(info);
    }

    @ApiOperation("查询单条记录")
    @GetMapping("/getById/{id}")
    public JsonData get(@PathVariable Long id) {
        return baseDictionaryService.get(id);
    }

    @ApiOperation("添加")
    @PostMapping("/add")
    public JsonData add(@RequestBody @Validated BaseDictionary baseDictionary) {
        return baseDictionaryService.add(baseDictionary);
    }

    @ApiOperation("修改")
    @PutMapping("/update")
    public JsonData update(@RequestBody @Validated BaseDictionary baseDictionary) {
        return baseDictionaryService.update(baseDictionary);
    }

    @ApiOperation("删除")
    @DeleteMapping("/delete/{id}")
    public JsonData delete(@PathVariable Long id) {
        return baseDictionaryService.delete(id);
    }

}
